import http from '@/utils/request'
import type { SysRoleForm, SysRoleQuery } from './types'
import type { AxiosPromise } from 'axios'

/**
 * 获取角色分页列表
 * @param data
 */
export const rolePage = (data?: SysRoleQuery) => {
  return http.request({
    url: '/api/v1/roles/page',
    method: 'post',
    data: data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

/**
 * 新增角色
 * @param roleForm
 */
export const addRole = (roleForm:SysRoleForm)=>{
  return http.request({
    url: '/api/v1/roles',
    method: 'post',
    data: roleForm,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 根据roleId获取角色表单数据
 * @param roleId
 */
export const getRoleForm = (roleId:number) => {
  return http.request({
    url: '/api/v1/roles/'+roleId+'/form',
    method: 'get',
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 根据roleId获取角色表单数据
 * @param roleId
 */
export const updateSysRoleForm = (sysRoleDto:SysRoleForm) => {
  let roleId = sysRoleDto.id;
  return http.request({
    url: '/api/v1/roles/'+roleId,
    method: 'put',
    data: sysRoleDto,
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 根据roleId删除角色
 * @param roleId
 */
export const deleteById = (roleId:string) => {
  return http.request({
    url: '/api/v1/roles/'+roleId,
    method: 'delete',
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

/**
 * 获取菜单下拉树形列表
 */
export const getRoleOptions = ():AxiosPromise<OptionType[]> =>  {
  return http({
    url: "/api/v1/role/getRoleOptions",
    method: "get",
    headers: {
      'Content-Type': 'application/json'
    }
  });
}
